package cn.javase.base.internet._02_TCP通讯._双向通讯;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        try(ServerSocket server = new ServerSocket(9999);
            Socket socket = server.accept();
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()))
        ) {
            String msg;
            while((msg = in.readLine()) != null) {
                System.out.println("服务端接受到的消息：" + msg);
                out.write("服务端接受到消息：" + msg + "\n");
                out.flush();
            }
        }
    }
}
